from django.shortcuts import render

# Create your views here.

from django.http.request import HttpRequest


from django.http.response import HttpResponse

def index(request):     # 参数request其实指的是line5导入的HttpRequest

    return HttpResponse('hello login !')


def book(request,cat_id,detail_id):


    # print(cat_id,detail_id)     la songs

    # query_string=request.GET
    # print(query_string)       # <QueryDict: {'a': ['111'], 'b': ['222']}>
    #
    # a=query_string['a']
    # b=query_string.get('b')
    # print(a)         # 111
    # print(b)       # 222


    query_string=request.GET
    print(query_string)        # <QueryDict: {'a': ['111', '666'], 'b': ['222']}>

    a=query_string['a']      # 存在丢失
    b=query_string.get('b')
    print(a,b)

    a=query_string.getlist('a')
    print(a)                  # ['111', '666']

    c=query_string.get('c','default')
    print(c)



    return HttpResponse('看书使我快乐')


def login(request):


    body=request.POST
    print(body)         # <QueryDict: {'name': ['lalala'], 'password': ['hello']}>



    return HttpResponse('DENG LU')

def weibo(request):


    body=request.body
    print(body)           # b'{\n\t"name":"itcast",\n\t"age":"12"\n}'
    body_str=body.decode()
    print(body_str)
    '''
    {
        "name":"itcast",
        "age":"12"
    }
    '''
    import json
    data=json.loads(body)
    print(data)
    # {'name': 'itcast', 'age': '12'}

    return HttpResponse('json 数据')